package com.tz.farmer.enums;

/**
 * @author kai
 * @Classname ErrorCode
 * @Description 错误码
 * @Date 2021/3/19 14:14
 * @Created kai
 */
public enum ErrorCodeEnum {
    /**
     * 错误码
     */
    ERR_COMMON_NO_DATA(100, "暂无数据"),
    ERR_COMMON_SUCCEED(200, "成功"),
    ERR_COMMON_INSERT_FAIL_ERROR(201, "新增失败，请重试"),
    ERR_COMMON_UPDATE_FAIL_ERROR(202, "修改失败，请重试"),
    ERR_COMMON_SELECT_FAIL_ERROR(203, "查询失败，请重试"),
    ERR_COMMON_DELETE_FAIL_ERROR(204, "删除失败，请重试"),
    ERR_COMMON_FAIL(205, "失败"),
    ERR_COMMON_ISSUE(206, "失败"),
    ERR_COMMON_FAIL_PRODUCT_CODE(208, "资产码错误"),
    ERR_COMMON_DELETE_ROLE_FAIL_ERROR(209, "该角色已绑定用户，禁止删除！"),
    ERR_COMMON_ALREADY_EXIST(207,"已存在数据，请重试"),
    ERR_COMMON_BAD_REQUEST(400,"参数错误"),
    ERR_COMMON_BAD_STOCK(601,"库存不够"),
    ERR_COMMON_DATA_REQUEST(410,"数据错误"),
    ERR_COMMON_ERROR_SERVER(500,"服务器内部错误"),
    ERR_COMMON_ERROR_IMPORT(10001,"导入失败"),
    ERR_COMMON_ERROR_EXPORT(10002,"导出失败"),
    ERR_COMMON_NO_ROLE_ERROR(10003,"角色已存在"),
    ERR_COMMON_USERNAME_PASSWORD_IS_NULL_ERROR(10005, "账号~密码不能为空"),
    ERR_COMMON_USERNAME_PASSWORD_IS_ERROR(10006, "密码错误"),
    ERR_COMMON_NO_USERNAME_ERROR(10007, "账号或密码错误"),
    ERR_COMMON_NO_ACCOUNT_ERROR(10008, "账户已存在"),
    ERR_COMMON_NOT_LOGGED_ERROR(10009, "用户未登录,请登录"),
    ERR_COMMON_LOGIN_EXPIRE_ERROR(10010, "登录已过期,请重新登录"),
    ERR_COMMON_TOKEN_IS_WRONG_ERROR(10011, "token错误,请重新登录"),
    ERR_COMMON_ACCOUNT_STATUS_FREEZE_ERROR(10012, "您的账号已被冻结,请联系工作人员"),
    ERR_COMMON_TOKEN_INCOMPLETE_INFORMATION_ERROR(10013, "令牌信息不完整")


    ;
    /**
     * 错误码
     */
    private int code;

    /**
     * 错误消息
     */
    private String message;

    ErrorCodeEnum(int code, String message) {
        this.message = message;
        this.code = code;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public static String getMessage(int code) {
        for (ErrorCodeEnum e : values()) {
            if (e.getCode() == code) {
                return e.getMessage();
            }
        }
        return "";
    }

}
